
<div class="conten">
	<div class="form_edit">
		<form id="form_value" action="<?php echo URL;?>category/create" method="post" accept-charset="utf-8">
			<table>
				<tbody>
					<tr>
						<td>Name<input type="hidden" value="" name="hidden" /></td>
						<td><input type="text" name="Name" /></td>
					</tr>
					<tr>
						<td>Path</td>
						<td><input type="text" name="Path" /></td>
					</tr>
					<tr>
						<td>Img</td>
						<td><input type="text" name="Img" /></td>
					</tr>
					<tr>
						<td></td>
						<td><input type="submit" name="submit" value="save" /></td>
					</tr>
				</tbody>
			</table>

		</form>
	</div>

	<div class="data-table">
		<table class="classic-table">
		<tr>
			<th>Id</th>
			<th>Name</th>
			<th>Path</th>
			<th>Img</th>
			<th></th>
			<th></th>
		</tr>
	<?php 
		foreach ($this->list_categories as $key => $value) {
			echo '<tr>';
			echo '<td>'.$value['Id'] . '</td>';
			echo '<td>'.$value['Name'] . '</td>';
			echo '<td>'.$value['Path'] . '</td>';
			echo '<td>'.$value['Img'] . '</td>';
			echo '<td><a class="link" href="'.URL.'category/edit_view/'.$value['Id'].'" >Edit</a> </td>';
			echo '<td><a class="link" href="'.URL.'category/delete/'.$value['Id'].'" >Delete</a></td>';
			echo '</tr>';
		}
		echo '</table>';
	?>
	</table>
	</div>
</div>
<script type="text/javascript">
		$(document).on('submit', '#form_value',function (){
			var url = $(this).attr('action');
		 	var pdata =  $(this).serializeObject();
			// Gui du lieu ve server xu ly
			$.post(url, pdata, function(o) {
				//data: Data from Server
				var success =  $(o).find('.conten').html(); 
				$('.conten').html(success);
				
			},'html').fail(function(jqXHR, textStatus, errorThrown){
				//fail
		     	
			});
			// Vi dung ajax nen phai tra ve false de form ko bi reload
			return false;
		});// end form sign up submit

		$(document).on('click', '.link',function() {
			var url = $(this).attr('href');
			$.post(url, '', function(o) {
				//data: Data from Server
				var success =  $(o).find('.conten').html(); 
				if(success == undefined){
					success =  $(o).find('.form_edit').html(); 
					$('.form_edit').html(success);
				}else {
					$('.conten').html(success);
				}
			},'html').fail(function(jqXHR, textStatus, errorThrown){
				//fail
		     	
			});
			return false;
		});
</script>
